<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="登记时间" prop="registrationTime">
        <el-date-picker clearable
          v-model="queryParams.registrationTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择登记时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="点小号" prop="clickTrumpet">
        <el-input
          v-model="queryParams.clickTrumpet"
          placeholder="请输入点小号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="点大号" prop="orderLarge">
        <el-input
          v-model="queryParams.orderLarge"
          placeholder="请输入点大号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="排活" prop="rowNumber">
        <el-input
          v-model="queryParams.rowNumber"
          placeholder="请输入排活"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上钟位置" prop="upclockPosition">
        <el-input
          v-model="queryParams.upclockPosition"
          placeholder="请输入上钟位置"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="叫钟人签字" prop="sign">
        <el-input
          v-model="queryParams.sign"
          placeholder="请输入叫钟人签字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="技师号" prop="technicianNumber">
        <el-input
          v-model="queryParams.technicianNumber"
          placeholder="请输入技师号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上钟时间" prop="clockTime">
        <el-date-picker clearable
          v-model="queryParams.clockTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择上钟时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="下钟时间" prop="nextClockTime">
        <el-date-picker clearable
          v-model="queryParams.nextClockTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择下钟时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="项目" prop="entryName">
        <el-input
          v-model="queryParams.entryName"
          placeholder="请输入项目"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班次" prop="sailings">
        <el-input
          v-model="queryParams.sailings"
          placeholder="请输入班次"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="建表时间" prop="tableCreationTime">
        <el-date-picker clearable
          v-model="queryParams.tableCreationTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择建表时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="客号" prop="handBrand">
        <el-input
          v-model="queryParams.handBrand"
          placeholder="请输入客号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="note">
        <el-input
          v-model="queryParams.note"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注1" prop="note1">
        <el-input
          v-model="queryParams.note1"
          placeholder="请输入备注1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注2" prop="note2">
        <el-input
          v-model="queryParams.note2"
          placeholder="请输入备注2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注3" prop="note3">
        <el-input
          v-model="queryParams.note3"
          placeholder="请输入备注3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注4" prop="note4">
        <el-input
          v-model="queryParams.note4"
          placeholder="请输入备注4"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注5" prop="note5">
        <el-input
          v-model="queryParams.note5"
          placeholder="请输入备注5"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注6" prop="note6">
        <el-input
          v-model="queryParams.note6"
          placeholder="请输入备注6"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注7" prop="note7">
        <el-input
          v-model="queryParams.note7"
          placeholder="请输入备注7"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注8" prop="note8">
        <el-input
          v-model="queryParams.note8"
          placeholder="请输入备注8"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注9" prop="note9">
        <el-input
          v-model="queryParams.note9"
          placeholder="请输入备注9"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注10" prop="note10">
        <el-input
          v-model="queryParams.note10"
          placeholder="请输入备注10"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['project:table:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['project:table:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['project:table:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['project:table:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tableList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="登记时间" align="center" prop="registrationTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.registrationTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="点小号" align="center" prop="clickTrumpet" />
      <el-table-column label="点大号" align="center" prop="orderLarge" />
      <el-table-column label="排活" align="center" prop="rowNumber" />
      <el-table-column label="上钟位置" align="center" prop="upclockPosition" />
      <el-table-column label="叫钟人签字" align="center" prop="sign" />
      <el-table-column label="技师号" align="center" prop="technicianNumber" />
      <el-table-column label="上钟时间" align="center" prop="clockTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.clockTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="下钟时间" align="center" prop="nextClockTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.nextClockTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目" align="center" prop="entryName" />
      <el-table-column label="班次" align="center" prop="sailings" />
      <el-table-column label="建表时间" align="center" prop="tableCreationTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.tableCreationTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="客号" align="center" prop="handBrand" />
      <el-table-column label="备注" align="center" prop="note" />
      <el-table-column label="备注1" align="center" prop="note1" />
      <el-table-column label="备注2" align="center" prop="note2" />
      <el-table-column label="备注3" align="center" prop="note3" />
      <el-table-column label="备注4" align="center" prop="note4" />
      <el-table-column label="备注5" align="center" prop="note5" />
      <el-table-column label="备注6" align="center" prop="note6" />
      <el-table-column label="备注7" align="center" prop="note7" />
      <el-table-column label="备注8" align="center" prop="note8" />
      <el-table-column label="备注9" align="center" prop="note9" />
      <el-table-column label="备注10" align="center" prop="note10" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['project:table:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['project:table:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改技师上钟情况对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="登记时间" prop="registrationTime">
          <el-date-picker clearable
            v-model="form.registrationTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择登记时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="点小号" prop="clickTrumpet">
          <el-input v-model="form.clickTrumpet" placeholder="请输入点小号" />
        </el-form-item>
        <el-form-item label="点大号" prop="orderLarge">
          <el-input v-model="form.orderLarge" placeholder="请输入点大号" />
        </el-form-item>
        <el-form-item label="排活" prop="rowNumber">
          <el-input v-model="form.rowNumber" placeholder="请输入排活" />
        </el-form-item>
        <el-form-item label="上钟位置" prop="upclockPosition">
          <el-input v-model="form.upclockPosition" placeholder="请输入上钟位置" />
        </el-form-item>
        <el-form-item label="叫钟人签字" prop="sign">
          <el-input v-model="form.sign" placeholder="请输入叫钟人签字" />
        </el-form-item>
        <el-form-item label="技师号" prop="technicianNumber">
          <el-input v-model="form.technicianNumber" placeholder="请输入技师号" />
        </el-form-item>
        <el-form-item label="上钟时间" prop="clockTime">
          <el-date-picker clearable
            v-model="form.clockTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择上钟时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="下钟时间" prop="nextClockTime">
          <el-date-picker clearable
            v-model="form.nextClockTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择下钟时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="项目" prop="entryName">
          <el-input v-model="form.entryName" placeholder="请输入项目" />
        </el-form-item>
        <el-form-item label="班次" prop="sailings">
          <el-input v-model="form.sailings" placeholder="请输入班次" />
        </el-form-item>
        <el-form-item label="建表时间" prop="tableCreationTime">
          <el-date-picker clearable
            v-model="form.tableCreationTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择建表时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="客号" prop="handBrand">
          <el-input v-model="form.handBrand" placeholder="请输入客号" />
        </el-form-item>
        <el-form-item label="备注" prop="note">
          <el-input v-model="form.note" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="备注1" prop="note1">
          <el-input v-model="form.note1" placeholder="请输入备注1" />
        </el-form-item>
        <el-form-item label="备注2" prop="note2">
          <el-input v-model="form.note2" placeholder="请输入备注2" />
        </el-form-item>
        <el-form-item label="备注3" prop="note3">
          <el-input v-model="form.note3" placeholder="请输入备注3" />
        </el-form-item>
        <el-form-item label="备注4" prop="note4">
          <el-input v-model="form.note4" placeholder="请输入备注4" />
        </el-form-item>
        <el-form-item label="备注5" prop="note5">
          <el-input v-model="form.note5" placeholder="请输入备注5" />
        </el-form-item>
        <el-form-item label="备注6" prop="note6">
          <el-input v-model="form.note6" placeholder="请输入备注6" />
        </el-form-item>
        <el-form-item label="备注7" prop="note7">
          <el-input v-model="form.note7" placeholder="请输入备注7" />
        </el-form-item>
        <el-form-item label="备注8" prop="note8">
          <el-input v-model="form.note8" placeholder="请输入备注8" />
        </el-form-item>
        <el-form-item label="备注9" prop="note9">
          <el-input v-model="form.note9" placeholder="请输入备注9" />
        </el-form-item>
        <el-form-item label="备注10" prop="note10">
          <el-input v-model="form.note10" placeholder="请输入备注10" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTable, getTable, delTable, addTable, updateTable } from "@/api/project/table";

export default {
  name: "Table",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 技师上钟情况表格数据
      tableList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        registrationTime: null,
        clickTrumpet: null,
        orderLarge: null,
        rowNumber: null,
        upclockPosition: null,
        sign: null,
        technicianNumber: null,
        clockTime: null,
        nextClockTime: null,
        entryName: null,
        sailings: null,
        tableCreationTime: null,
        handBrand: null,
        note: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询技师上钟情况列表 */
    getList() {
      this.loading = true;
      listTable(this.queryParams).then(response => {
        this.tableList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        registrationTime: null,
        clickTrumpet: null,
        orderLarge: null,
        rowNumber: null,
        upclockPosition: null,
        sign: null,
        technicianNumber: null,
        clockTime: null,
        nextClockTime: null,
        entryName: null,
        sailings: null,
        tableCreationTime: null,
        handBrand: null,
        note: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加技师上钟情况";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTable(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改技师上钟情况";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTable(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTable(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除技师上钟情况编号为"' + ids + '"的数据项？').then(function() {
        return delTable(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('project/table/export', {
        ...this.queryParams
      }, `table_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
